//
//  UserCell.m
//  zhijian
//
//  Created by yiban on 2019/1/22.
//  Copyright © 2019 lcb. All rights reserved.
//

#import "UserCell.h"
#import <SDAutoLayout/SDAutoLayout.h>
#import "QuestionModel.h"
#import "CommentModel.h"
@interface UserCell ()

@property (strong, nonatomic) UIImageView *iconImg;
@property (strong, nonatomic) UILabel *lblNick;
@property (strong, nonatomic) UILabel *lblFrom;
@property (strong, nonatomic) UILabel *lbltime;
@end
@implementation UserCell

- (instancetype)init
{
    if (self = [super init]) {
        [self setup];
    }
    return self;
}
-(void)setup{
    //
    _iconImg = [UIImageView new];
    _iconImg.image = [UIImage imageNamed:@"avater"];
    //设置边框圆角的弧度
    [_iconImg.layer setMasksToBounds:YES];
    [_iconImg.layer setCornerRadius:50 / 2.0];
    _iconImg.userInteractionEnabled = YES;
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
//    [_iconImg addGestureRecognizer:tap];
    //
    _lblNick = [UILabel new];
    _lblNick.font = [UIFont systemFontOfSize:14];
    _lblNick.textColor=UIColorOfHex(0x333333);
    
    //
    _lblFrom = [UILabel new];
    _lblFrom.font = [UIFont systemFontOfSize:11];
    _lblFrom.textColor=UIColorOfHex(0x999999);
    _lblFrom.numberOfLines=1;
    //
    _lbltime = [UILabel new];
    _lbltime.font = [UIFont systemFontOfSize:11];
    _lbltime.textColor=UIColorOfHex(0x999999);
    _lbltime.numberOfLines=1;
    _lbltime.textAlignment = NSTextAlignmentRight;
    //
    [self sd_addSubviews:@[_iconImg,_lblNick, _lblFrom,_lbltime]];
    self.sd_equalWidthSubviews = @[_iconImg,_lblNick, _lblFrom,_lbltime];
    
    // 设置约束
    CGFloat margin = 10;
    
    //
    _iconImg.sd_layout
    .leftSpaceToView(self,margin)
    .topSpaceToView(self,margin)
    .widthIs(50)
    .heightIs(50);
    
    _lblNick.sd_layout
    .leftSpaceToView(_iconImg,margin)
    .topSpaceToView(self,margin)
    .autoHeightRatio(0);
    [_lblNick setMaxNumberOfLinesToShow:1];
    [_lblNick setSingleLineAutoResizeWithMaxWidth:SCREEN_WIDTH-160];
    //
    _lblFrom.sd_layout
    .leftSpaceToView(_iconImg,margin)
    .topSpaceToView(_lblNick,margin/2)
    .widthIs(SCREEN_WIDTH-80)
    .autoHeightRatio(0);
    [_lblFrom setMaxNumberOfLinesToShow:1];
    //
    _lbltime.sd_layout
    .rightSpaceToView(self,10)
    .topSpaceToView(self,10)
    .widthIs(SCREEN_WIDTH/2)
    .heightIs(20);
    
}
-(void)setBaseModel:(BaseModel *)baseModel
{
    NSLog(@"usercell -----setZhiJianModel");
    _baseModel = baseModel;
    if ([baseModel isKindOfClass:[QuestionModel class]]) {
        QuestionModel *qModel = (QuestionModel *)baseModel;
        [self.iconImg imageWithUrlStr:qModel.userHeadImg placeholder:[UIImage imageNamed:@"avater"]];
        self.lblNick.text = qModel.userName;
        self.lblFrom.text = qModel.companyName;
        self.lbltime.text = qModel.questionTimeDesc;
    }
    if ([baseModel isKindOfClass:[CommentModel class]]) {
        CommentModel *qModel = (CommentModel *)baseModel;
        [self.iconImg imageWithUrlStr:qModel.userHeadImg placeholder:[UIImage imageNamed:@"avater"]];
        self.lblNick.text = qModel.userName;
        self.lblFrom.text = qModel.userTitle;
        self.lbltime.text = qModel.commentTimeDesc;
    }
    [self updateLayout];
}


@end
